{% extends 'CuteFlowCoreBundle::admin.html.twig' %}

{% block javascripts %}
    {{ parent() }}
    <script src="{{ asset('bundles/cuteflowcore/js/form_helper.js') }}" type="text/javascript"></script>
{% endblock %}
{% block title %}{{ parent() }} - {{ "user.title.administration" | trans }}{% endblock %}



{% block contextual %}
    <a class="icon icon-add" href="{{ path('cuteflow_admin_user_create') }}">{{ "user.label.new_user" | trans }}</a>
{% endblock %}

{% block body %}
    <h2>{{ "user.header.user" | trans }}</h2>

    {% if (app.session.hasFlash('saved.successful')) %}
        <div class="flash notice">
            {{ "user.message.user_successfully_saved" | trans }}
        </div>
        <br/>
    {% endif %}

    {% if (app.session.hasFlash('deleted.successful')) %}
        <div class="flash notice">
            {{ "user.message.user_successfully_saved" | trans }}
        </div>
        <br/>
    {% endif %}

    <table class="list">
      <thead>
        <tr>
          <th>&nbsp;</th>
          <th>{{ "user.label.firstname" | trans }}</th>
          <th>{{ "user.label.lastname" | trans }}</th>
          <th>{{ "user.label.email" | trans }}</th>
          <th>{{ "user.label.username" | trans }}</th>
          <th>{{ "user.label.administrator" | trans }}</th>
          <th>{{ "user.label.last_login" | trans }}</th>
          <th>&nbsp;</th>
        </tr>
      </thead>
      <tbody>
        {% for user in paginator %}
            <tr class="{{ cycle(['odd', 'even'], loop.index) }}">
                <td><img class="gravatar" width="14" height="14" src="{{ gravatar(user.email, 14) }}" /></td>
                <td>{{ user.lastName }}</td>
                <td>{{ user.firstName}}</td>
                <td>{{ user.email}}</td>
                <td>{{ user.username}}</td>
                <td style="text-align: center">
                    {% if user.hasRole('ROLE_CUTEFLOW_ADMIN') %}
                        <img src="/bundles/cuteflowcore/images/toggle_check.png" alt="yes">
                    {% endif %}
                </td>
                <td>{{ user.getGroupNames() | join(', ') }}</td>
                <td>{{ user.lastLogin | localedate() }}</td>
                <td>
                    <small><a href="{{ path('cuteflow_admin_user_edit', {'id': user.id}) }}" class="icon icon-edit">{{ "user.label.edit" | trans }}</a></small>
                    <small><a href="{{ path('cuteflow_admin_user_delete', {'id': user.id}) }}" onclick="return confirm('{{ "user.message.really_delete" | trans }}')" class="icon icon-del">{{ "user.label.delete" | trans }}</a></small>
                </td>
            </tr>
        {% endfor %}
      </tbody>
    </table>
    <p class="pagination">
        {{ pagerfanta(paginator, 'default') }}
    </p>
{% endblock %}

{% block sidebar %}
    <h3>{{ "user.header.filter" | trans }}</h3>
    <div class="filter">
        <form action="{{ path('cuteflow_admin_user', {'page': paginator.currentPage})}}" id="filter-form" method="POST">
            {{ form_row(filterForm.lastname) }}
            {{ form_row(filterForm.firstname) }}
            {{ form_row(filterForm.username) }}
            {{ form_row(filterForm.group) }}

            <input type="submit" value="{{ "user.button.filter" | trans }}"/>&nbsp;&nbsp;&nbsp;
            <input type="button" value="{{ "user.button.reset_filter" | trans }}"/>
      </form>
    </div>
{% endblock %}
